package com.zff.rental.controller.dict;


import com.zff.rental.AppConstant;
import com.zff.rental.common.Result;
import com.zff.rental.entity.dict.KeyValueDict;
import com.zff.rental.service.dict.KeyValueDictServer;
import com.zff.rental.vo.dict.KeyValueDictIdParams;
import com.zff.rental.vo.dict.KeyValueDictParams;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 字典
 *
 * @author HCY
 */
@RestController
@RequestMapping(AppConstant.RM_DICT)
public class KeyValueDictController {
    @Resource
    private KeyValueDictServer keyValueDictServer;

    /**
     * 添加或修改字典
     */
    @PostMapping("/addOrModify")
    public Result<KeyValueDict> add(@Validated @RequestBody KeyValueDictParams params) {
        KeyValueDict result = keyValueDictServer.add(params);
        return Result.success(result);
    }

    /**
     * 删除字典
     */
    @PostMapping("/remove")
    public Result<Boolean> remove(@Validated @RequestBody KeyValueDictIdParams params) {
        Boolean result = keyValueDictServer.remove(params);
        return Result.success(result);
    }

    /**
     * 批量修改
     */
    @PostMapping("/batchModify")
    public Result<List<KeyValueDict>> batchModify(@Validated @RequestBody List<KeyValueDictParams> params) {
        List<KeyValueDict> result = keyValueDictServer.batchModify(params);
        return Result.success(result);
    }

    /**
     * 根据字典类型获取字典列表
     */
    @GetMapping("/listByType")
    public Result<List<KeyValueDict>> listByType(@RequestParam("type") Integer type) {
        List<KeyValueDict> result = keyValueDictServer.listByType(type);
        return Result.success(result);
    }

    /**
     * 根据字典类型列表获取分组字典
     */
    @PostMapping("/listByTypes")
    public Result<Map<Integer, List<KeyValueDict>>> listByTypes(@RequestBody List<Integer> types) {
        Map<Integer, List<KeyValueDict>> result = keyValueDictServer.listByTypes(types);
        return Result.success(result);
    }
}
